package gridview;

import java.util.ArrayList;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.os.Bundle;
import android.widget.GridView;

import com.unipv14.androidgallery.R;

import fileManagers.FileUtilities;

public class GridViewActivity extends Activity {

		private GridView gridView;
		private GridViewAdapter customGridAdapter;
		
		@Override
		protected void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			setContentView(R.layout.grid_view_image);

			gridView = (GridView) findViewById(R.id.gridView);
			customGridAdapter = new GridViewAdapter(this,
					R.layout.row_grid, getData(),getList());
			gridView.setAdapter(customGridAdapter);
		}
		
		private String[] getList(){
			return getIntent().getExtras().getStringArray("list");
		}
		
		private ArrayList<ImageItem> getData() {
			String[] list=getList();
			ArrayList<ImageItem> items=new ArrayList<ImageItem>(); 
			if(list==null){
				return items;
			}
			Options options=new Options();
			options.inSampleSize=16;
			for(int i=0;i<list.length;i++){
				Bitmap bitmap=BitmapFactory.decodeFile(list[i], options);
				items.add(new ImageItem(bitmap, FileUtilities.pathToName(list[i])));
			}
			return items;
		}
  }	    
	    
